﻿using AOT;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using Smart.Model;

public class CppLog : MonoBehaviour
{
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]

    public delegate void LogDelegate(IntPtr message, int iSize);

    [DllImport("recast", CallingConvention = CallingConvention.Cdecl)]
    static extern void SetupLogDelegate(LogDelegate log);

    //C# Function for C++‘s call
    [MonoPInvokeCallback(typeof(LogDelegate))]

    public static void LogMessageFromCpp(IntPtr message, int iSize)
    {
        Debug.Log(Marshal.PtrToStringAnsi(message, iSize));
    }

    private void Awake()
    {
        Log.Info("[C++动态库日志插件]:启动成功...");
        SetupLogDelegate(LogMessageFromCpp);
    }
}
